package com.oocl.shopping.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.oocl.shopping.dao.CustomerDao;
import com.oocl.shopping.dao.OrderDao;
import com.oocl.shopping.dao.impl.CustomerDaoImpl;
import com.oocl.shopping.dao.impl.OrderDaoImpl;
import com.oocl.shopping.dto.PayBooksDTO;
import com.oocl.shopping.pojo.Customer;
import com.oocl.shopping.pojo.Order;
import com.oocl.shopping.service.CustomerService;

public class CustomerServiceImpl implements CustomerService{

	private CustomerDao customerDao;
	private OrderDao orderDao;
	
	public CustomerServiceImpl() {
		customerDao = new CustomerDaoImpl();
		orderDao = new OrderDaoImpl();
	}

	@Override
	public boolean isNameFmt(String name) {
		String nameRegex = "^(([\u4e00-\u9fa5]{2,8})|([a-zA-Z]{2,16}))$";
		Pattern p = Pattern.compile(nameRegex);
		Matcher m = p.matcher(name);
		if(m.matches()){
			return true;
		}
		return false;
	}

	@Override
	public Customer findCustomer(String name, String pwd) {
		return customerDao.findCustomer(name, pwd);
	}

	@Override
	public boolean addOneOrder(String bookId, String custId) {
		return orderDao.addOneOrder(bookId, custId);
	}

	@Override
	public boolean delOneOrder(String orderId, String custId) {
		return orderDao.delOneOrder(orderId, custId);
	}

	@Override
	public boolean delAllOrder(String custId) {
		return orderDao.delAllOrder(custId);
	}

	@Override
	public List<PayBooksDTO> getOrders(String custId) {
		return orderDao.getOrders(custId);
	}

	@Override
	public boolean addOrders(String custId, Map<String, PayBooksDTO> orders) {
		return orderDao.addOrders(custId, orders);
	}

}
